import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 引入多个模块的规则
import departments from './modules/departments'
import employees from './modules/employees'
import setting from './modules/setting'
import salarys from './modules/salarys'
import social from './modules/social'
import attendances from './modules/attendances'
import approvals from './modules/approvals'
import permission from './modules/permission'
// 再准备一个放动态路由的数组
// 如果你再额外准备这个数组，那么到时候就根据权限可以决定这个数组里放哪些规则
// 可以根据权限来添加和删除
export const aysncRoutes = [
  departments,
  employees,
  permission,
  social,
  attendances,
  salarys,
  approvals,
  setting
]


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path:'/myinfo',
    component:Layout,
    hidden:true,
    children:[{
      path:'',
      component: () => import('@/views/myinfo/index.vue')
    }]
  },

  {
    path:'/import',
    component:Layout,
    hidden:true,
    children:[{
      path:'',
      component: () => import('@/views/import/index.vue')
    }]
  },

  // 404 page must be placed at the end !!!

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }), // 管理滚动行为 如果出现滚动 切换就让 让页面回到顶部
  routes: [...constantRoutes] // 临时合并所有的路由
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
